import java.util.ArrayList;

public class Team
{
    public Team()
    {
    }

    public String name = "";
    public ArrayList<Student> students = new ArrayList<Student>();
    public ArrayList<Issue> issues = new ArrayList<Issue>();

    String getLabel()
    {
        if (students.isEmpty()) return name + " (empty)";
        String out = name + " (";
        int s = students.size();
        for (int i = 0; i < s; i++)
        {
            String n = students.get(i).name;
            if (n.contains(",")) n = n.substring(0, n.indexOf(","));
            out = out + n;
            if (i < s-1) out = out + ", ";
        }
        return out + ")";
    }

    String labelToName(String label)
    {
        return label.substring(0,label.indexOf('(')-1);
    }

    public void freeStudents()
    {
        for (int i = 0; i < students.size(); i++)
        {
            students.get(i).team = null;
        }
        students.clear();
    }

    public void addStudent(Student s)
    {
        if (students.contains(s)) return;

        students.add(s);
        if (s.team != null)
        {
            s.team.removeStudent(s);
        }
        s.team = this;
    }

    private void removeStudent(Student s)
    {
        if (!students.contains(s)) return;
        students.remove(s);
        s.team = null;
    }
}
